package cn.achuan.spring.springcloud.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.web.client.RestTemplate;

// 声明这是一个Eureka Client
@EnableDiscoveryClient
@SpringBootApplication
public class Application {

    /**
     * 添加依赖 spring-cloud-starter-netflix-ribbon 以及在 RestTemplate 增加了
     * 一个 @LoadBalanced 注解，该注解就是能够让 RestTemplate 启用客户端负载均衡。
     */
    @Bean
    @LoadBalanced
    RestTemplate restTemplate() {
        return new RestTemplate();
    }

    @Primary
    @Bean(name="lbcRestTemplate")
    RestTemplate lbcRestTemplate() {
        return new RestTemplate();
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}